from docx import Document
from pptx import Presentation


def add_word_to_ppt_notes(word_file, ppt_file):
    doc = Document(word_file)
    prs = Presentation(ppt_file)

    current_title = None
    current_content = []

    for paragraph in doc.paragraphs:
        if paragraph.style.name.startswith('Heading 1'):
            if current_title is not None:
                add_content_to_slide(current_title, current_content, prs)

            current_title = paragraph.text
            current_content = []
        else:
            current_content.append(paragraph.text)

    if current_title is not None:
        add_content_to_slide(current_title, current_content, prs)

    prs.save('outputnew.pptx')


def add_content_to_slide(title, content, prs):
    slide = prs.slides.add_slide(prs.slide_layouts[5])  # 使用"标题 + 正文"布局
    notes_slide = slide.notes_slide
    notes_shape = notes_slide.notes_text_frame

    notes_shape.text = f"{title}\n{' '.join(content)}"



if __name__ == '__main__':
    add_word_to_ppt_notes('人工智能.docx', 'output.pptx')
